package com.ruoyi.eservice.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eservice.pojo.entity.Policy;
import com.ruoyi.eservice.service.IPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区域的疫情政策信息Controller
 *
 * @author fencheng
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/einfo/policy")
public class PolicyController extends BaseController
{
    @Autowired
    private IPolicyService policyService;

    /**
     * 查询区域的疫情政策信息列表
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Policy policy)
    {
        startPage();
        List<Policy> list = policyService.selectPolicyList(policy);
        return getDataTable(list);
    }

    /**
     * 导出区域的疫情政策信息列表
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:export')")
    @Log(title = "区域的疫情政策信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Policy policy)
    {
        List<Policy> list = policyService.selectPolicyList(policy);
        ExcelUtil<Policy> util = new ExcelUtil<Policy>(Policy.class);
        util.exportExcel(response, list, "区域的疫情政策信息数据");
    }

    /**
     * 获取区域的疫情政策信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:query')")
    @GetMapping(value = "/{policyId}")
    public AjaxResult getInfo(@PathVariable("policyId") Long policyId)
    {
        return AjaxResult.success(policyService.selectPolicyByPolicyId(policyId));
    }

    /**
     * 新增区域的疫情政策信息
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:add')")
    @Log(title = "区域的疫情政策信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Policy policy)
    {
        return toAjax(policyService.insertPolicy(policy));
    }

    /**
     * 修改区域的疫情政策信息
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:edit')")
    @Log(title = "区域的疫情政策信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Policy policy)
    {
        return toAjax(policyService.updatePolicy(policy));
    }

    /**
     * 删除区域的疫情政策信息
     */
    @PreAuthorize("@ss.hasPermi('einfo:policy:remove')")
    @Log(title = "区域的疫情政策信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policyIds}")
    public AjaxResult remove(@PathVariable Long[] policyIds)
    {
        return toAjax(policyService.deletePolicyByPolicyIds(policyIds));
    }

    /**
     * 通过传入的地区名获取政策信息
     * @param areaname
     * @return
     */
    @GetMapping("/areaname")
    public AjaxResult areaPolicy(@RequestParam("areaname") String areaname){

        return policyService.getPolicyByName(areaname);

    }


}
